package com.ruoyi.robot.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.robot.pojo.po.RobotType;
import com.ruoyi.robot.pojo.dto.RobotTypeDto;
import com.ruoyi.robot.service.RobotTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  机器人类别前端控制器
 * </p>
 *
 * @author yid
 * @since 2023-01-16
 */
@Api(tags = "机器人类别接口")
@RestController
@RequestMapping("/robot/robotType")
public class RobotTypeController extends BaseController {

    private final RobotTypeService robotTypeService;

    @Autowired
    public RobotTypeController(RobotTypeService robotTypeService) {
        this.robotTypeService = robotTypeService;
    }

    /**
     * 查询机器人类型列表
     */
    @ApiOperation("查询机器人类型列表")
    @GetMapping("/list")
    public TableDataInfo list(RobotTypeDto robotTypeDto)
    {
        startPage();
        List<RobotType> list = robotTypeService.selectRobotTypeList(robotTypeDto);
        return getDataTable(list);
    }

    /**
     * 导出机器人类型列表
     */
    @ApiOperation("导出机器人类型列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, RobotTypeDto robotTypeDto)
    {
        List<RobotType> list = robotTypeService.selectRobotTypeList(robotTypeDto);
        ExcelUtil<RobotType> util = new ExcelUtil<RobotType>(RobotType.class);
        util.exportExcel(response, list, "机器人类型数据");
    }

    /**
     * 获取机器人类型详细信息
     */
    @ApiOperation("获取单个机器人类型信息")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(robotTypeService.selectRobotTypeByTypeId(typeId));
    }

    /**
     * 新增机器人类型
     */
    @ApiOperation("新增机器人类型")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody RobotTypeDto robotTypeDto)
    {
        return robotTypeService.insertRobotType(robotTypeDto);
    }

    /**
     * 修改机器人类型
     */
    @ApiOperation("修改机器人类型")
    @PutMapping
    public AjaxResult edit(@RequestBody RobotTypeDto robotTypeDto)
    {
        return toAjax(robotTypeService.updateRobotType(robotTypeDto));
    }

    /**
     * 删除机器人类型
     */
    @ApiOperation("删除机器人类型")
    @DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(robotTypeService.deleteRobotTypeByTypeIds(typeIds));
    }

    /**
     *
     * @param file
     * @return
     */
    @PostMapping("/uploadPicture")
    public AjaxResult uploadPicture(@RequestParam(value="file",required=false) @RequestPart("file") MultipartFile file) {
        return robotTypeService.uploadPicture(file);
    }
}

